import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
import i18n from '@/lang' // 语言(挂载在实例上)

// 导入全局注册组件
import component from './components/index.js'
Vue.use(component) // 注册自己的插件(组件)

// 引入指令模块(自动化注册)
import * as directives from '@/directives/index'
Object.keys(directives).forEach(key => {
  Vue.directive(key, directives[key])
})

// 引入过滤器模块(自动化注册)
import * as filters from '@/filters/index'
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale }) // locale为语言包

// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
Vue.use(ElementUI, {
  // elementUI 本身支持i18n的处理
  // 此时i18n就会根据当前的local属性去匹配对应的语言包
  i18n: (key, value) => i18n.t(key) // t方法 会去对应语言包里寻找对应的内容
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router, // 挂载到实例上
  store, // 挂载到实例上
  i18n, // 挂载到实例上
  render: h => h(App)
})
